﻿using GoPlay.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GoPlay.Tests.Models
{
    public class InMemoryTeamRepository : ITeamRepository
    {
        private List<Team> _db = new List<Team>();

        public Exception ExceptionToThrow { get; set; }
        //public List<Contact> Items { get; set; }

        public Team GetTeamByID(int id)
        {
            return _db.FirstOrDefault(d => d.Id == id);
        }

        public IEnumerable<Team> GetAllTeamsForUser(int userId)
        {
            return _db.ToList();
        }

        public int CreateNewTeam(Team team)
        {
            if (ExceptionToThrow != null)
                throw ExceptionToThrow;

            _db.Add(team);
            return 1;
        }

        public int SaveChanges()
        {
            return 1;
        }

        public void DeleteTeam(int id)
        {
            _db.Remove(GetTeamByID(id));
        }

        public void UpdateTeam(Team team)
        {
            if (ExceptionToThrow != null)
                throw ExceptionToThrow;

            var t = GetTeamByID(team.Id);
            t.Name = team.Name;
        }
    }
}
